<template>
  <div class="tab-bar-item" @click="itemClick">
    <!-- 使用div包裹插槽是因为防止某些属性被替换后失效 -->
    <div
      :style="activeStyle"
      class="box animated  nav-bottom"
      :class="{ zoomIn: isActive }"
    >
      <slot name="item-text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabBarItem",
  props: {
    path: String /* 从父组件app传来的path */,
    activeColor: {
      type: String,
      default: "#979899"
    }
  },
  data() {
    return {
      // isActive: false
    };
  },
  computed: {
    /* 激活后的状态图片切换*/
    isActive() {
      return this.$route.path.indexOf(this.path) !== -1;
    },
    /* 动态绑定样式 */
    activeStyle() {
      return this.isActive ? { color: this.activeColor } : {};
    }
  },
  methods: {
    itemClick() {
      if (this.path) this.$router.push(this.path);
    }
  }
};
</script>

<style scoped lang="scss">
.tab-bar-item {
  /* 元素居中 */
  flex: 1;
  text-align: center;
  height: 10vh;
  font-size: 18px;
  font-weight: bold;
  // margin-top: 3px;
  color: var(--color-nav-title);
  line-height: 10vh;
  .nav-bottom {
    box-sizing: border-box;
    // background-color:red;
    // border-bottom: aqua 3px outset;
  }
  :hover {
    cursor: pointer;
    // cursor: url("/assets/image/common/coursor.ico"), auto;
    color: #979899;
  }
}
</style>
